
$(function() {
	Tip.emp('员工');
	
	$('#date1').datepicker(_date1_option);
	$('#date1').change(function() {
		$('#date2').val($(this).val());
	});

	$('#date2').datepicker(_date1_option);
	
	$('#time_t').change(function() {
		var s = $(this).val();
		time(s);		
	});

	$('textarea').css("width", 400);
	
	var grid;
	var columns = [{
	    id: "#",
	    name: "",
	    width: 40,
	    behavior: "selectAndMove",
	    unselectable: true,
	    resizable: false,
	    cssClass: "cell-reorder"
	}, {
	    id: "mold",
	    name: "产品",
	    field: "mold_x",
	    width: 150,
	    cssClass: "cell-title",
	    editor: MoldCellEditor
	}, {
	    id: "machine",
	    name: "机台",
	    field: "machine",
	    width: 150,
	    cssClass: "cell-title",
	    editor: MachineCellEditor
	}, {
	    id: "worker",
	    name: "员工",
	    field: "worker",
	    width: 100,
	    cssClass: "cell-title",
	    editor: EmpCellEditor,
	    validator: requiredFieldValidator
	}, {
	    id: "content",
	    name: "备注",
	    field: "content",
	    width: 140,
	    cssClass: "cell-title",
	    editor: Slick.Editors.Text,
	    validator: requiredFieldValidator
	}, {
	    id: "ok",
	    name: "",
	    field: "ok",
	    width: 80,
	    cssClass: "cell-effort-driven",	    
	    cannotTriggerInsert: true,
	    formatter: Slick.Formatters.YesNo,
	    editor: Slick.Editors.Checkbox
	}];

	var options = {
			editable: true,
		    enableAddRow: true,
		    enableCellNavigation: true,
		    asyncEditorLoading: false,
		    rowHeight: 30
		};	
	
	grid = new Slick.Grid($("#myGrid"), data, columns, options);
	
	grid.onAddNewRow.subscribe(function (e, args) {
	// grid.onAddNewRow = function addItem(newItem,columnDef) {
        var item = {mold_x:"", machine:"", worker:"", content:"", ok: true};
        
        $.extend(item, args.item);
        data.push(item);
        grid.invalidateRows([data.length - 1]);
        grid.updateRowCount();
        grid.render();
        
        // total();
    });
});